* Table A19:  Missingness and Low Income in the 1948-1953 and 1961-1964 Cohorts
clear
use "${data_dir}DavisMazumderData.dta"

keep if age_firstSurvey<=18
drop if (mom_outOfRange==1 & linkMom==1 & !(dad_outOfRange==0 & linkDad==1)) | (dad_outOfRange==1 & linkDad==1 & !(mom_outOfRange==0 & linkMom==1)) | (linkMom==0 & linkDad==0) 
 


gen inSample0 = 1-miss0
gen inSample1 = 1-miss1
gen inSample = inSample0 & inSample1

matrix both = J(3,6,.)
local row = 0
foreach var of varlist inSample inSample0 inSample1  {
	local row = `row'+1
	su `var' if surv79==0 [w=weight] 
	matrix both[`row',1] = r(mean)
	su `var' if surv79==1 [w=weight] 
	matrix both[`row',2] = r(mean)
	su `var' if surv79==0 & women==1 [w=weight] 
	matrix both[`row',3] = r(mean)
	su `var' if surv79==1 & women==1 [w=weight] 
	matrix both[`row',4] = r(mean)
	su `var' if surv79==0 & women==0 [w=weight] 
	matrix both[`row',5] = r(mean)
	su `var' if surv79==1 & women==0 [w=weight] 
	matrix both[`row',6] = r(mean)
}



keep if miss1==0 & miss0==0


matrix parent_det = J(10,6,.)

forv i=1/3 {
	gen low_parent`i' = parent`i'>0 & parent`i'<=1500
	replace parent`i' = . if low_parent`i'==1 | ms_parent`i' | zero_parent`i'
}

local row = 0
foreach var of varlist  nparent_1500 ms_parent1 ms_parent2 ms_parent3 zero_parent1 zero_parent2 zero_parent3 low_parent1 low_parent2 low_parent3 {
	local row = `row'+1
	su `var' if surv79==0 [w=weight] 
	matrix parent_det[`row',1] = r(mean)
	su `var' if surv79==1 [w=weight] 
	matrix parent_det[`row',2] = r(mean)
	su `var' if surv79==0 & women==1 [w=weight] 
	matrix parent_det[`row',3] = r(mean)
	su `var' if surv79==1 & women==1 [w=weight] 
	matrix parent_det[`row',4] = r(mean)
	su `var' if surv79==0 & women==0 [w=weight] 
	matrix parent_det[`row',5] = r(mean)
	su `var' if surv79==1 & women==0 [w=weight] 
	matrix parent_det[`row',6] = r(mean)
}



matrix child_det = J(10,6,.)

forv i=1/3 {
	gen low_kid`i' = kid`i'>0 & kid`i'<=1500
	replace kid`i' = . if low_kid`i'==1 | ms_kid`i' | zero_kid`i'
}


local row = 0
foreach var of varlist  nkid_1500 ms_kid1 ms_kid2 ms_kid3  zero_kid1 zero_kid2 zero_kid3 low_kid1 low_kid2 low_kid3 {
	local row = `row'+1
	su `var' if surv79==0 [w=weight] 
	matrix child_det[`row',1] = r(mean)
	su `var' if surv79==1 [w=weight] 
	matrix child_det[`row',2] = r(mean)
	su `var' if surv79==0 & women==1 [w=weight] 
	matrix child_det[`row',3] = r(mean)
	su `var' if surv79==1 & women==1 [w=weight] 
	matrix child_det[`row',4] = r(mean)
	su `var' if surv79==0 & women==0 [w=weight] 
	matrix child_det[`row',5] = r(mean)
	su `var' if surv79==1 & women==0 [w=weight] 
	matrix child_det[`row',6] = r(mean)
}



clear
svmat both
forv i=1/6 {
	ren both`i' c`i'
}
tempfile both
save `both'

clear
svmat parent_det
forv i=1/6 {
	ren parent_det`i' c`i'
}
tempfile parent_det
save `parent_det'

clear
svmat child_det
forv i=1/6 {
	ren child_det`i' c`i'
}
tempfile child_det
save `child_det'

clear
append using `both'
append using `parent_det'
append using `child_det'

outsheet using ${results_dir}tableA19.csv, comma names replace

exit

